import Vue from 'vue'
import Vuex from 'vuex'

import {
		getQuestions,
	} from '@/api/file.js'
import login from "../pages/login/login";
Vue.use(Vuex)

const actions = {
	async getQuestions(context, input){
		//console.log("weee:",input);
		//发起数据请求
		await getQuestions(input).then(res => {
			 // console.log("questions:",res);
			 context.commit("GetQuestions",res.data.data)
		})},
}
const mutations = {
	GetQuestions(state,data) {
		 state.questions = data;
		console.log("获取的questions:", state.questions);
	},
		//state.answer=[];  //初始开始将answer清空，防止多门考试题目答案累加
	// 	state.completionAnswer = [];  //初始开始将completionAnswer清空，防止多门考试填空题目答案累加
	// 	console.log("获取的questions2:",state.questions);
	// 	for (var i=0;i<state.questions.length;i++){
	// 		if (state.questions[i].type=="选择题")
	// 			state.answer.push({type:"选择题",answerText:"F"});
	// 		else if (state.questions[i].type=="判断题")
	// 			state.answer.push({type:"判断题",answerText:"F"});
	// 		else if (state.questions[i].type=="填空题"){
	// 			state.answer.push({type:"填空题",answerText:"F"});
	// 			let num = state.questions[i].text.match("()").length
	// 			const A = {answer: []};
	// 			A.answer = new Array(num);
	// 			state.completionAnswer.push(A)
	// 		}
	// 		else if (state.questions[i].type=="简答题")
	// 			state.answer.push({type:"简答题",answerText:"F"});
	// 	}
	// 	console.log("state的填空题",state.completionAnswer)
	// 	console.log("InitAnswer的answer",state.answer)
	// },
	GetAnswer(state,data){
		console.log(state.questions)
		state.questions[data.number].answer[0]=data.text;
		//console.log("index中的getAnswer的questions",state.questions)
	},
}
const state = {
	questions: [],
	testId:'',
	testMsg:{},
	questionMsg:[],//考生答案
}

export default new Vuex.Store(
{
	actions,
	mutations,
	state,
})